package com.shop.front.config;

import com.shop.front.interceptor.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private UserInterceptor userInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userInterceptor).addPathPatterns("/**")
                 // --- 过滤 登录注册
                .excludePathPatterns("/lr/**")
                // --- 过滤 首页、商品、分类
                .excludePathPatterns("/index/**")
                .excludePathPatterns("/storeProduct/**")
                .excludePathPatterns("/storeCategory/**")
                .excludePathPatterns("/system/**")
                .excludePathPatterns("/article/**")
                .excludePathPatterns("/api/**")
                .excludePathPatterns("/callBack/**")
                .excludePathPatterns("/wxpay/**")
                .excludePathPatterns("/page/**")
                // --- 过滤订单状态同步
                .excludePathPatterns("/storeOrder/checkPayStatus")
                .excludePathPatterns("/userPink/checkPinkPayStatus")
                // --- 过滤 webjars
                .excludePathPatterns("/webjars/**")
                // --- 过滤 swagger - doc
                .excludePathPatterns("/swagger-ui.html")
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/v2/**")
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/error")
                ;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}
